<% add_decidim_page_title(t("conference_speakers.index.conference_speakers_title", scope: "decidim.admin")) %>

<div class="card" id="conference_speakers">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t("conference_speakers.index.conference_speakers_title", scope: "decidim.admin") %>
      <% if allowed_to? :create, :conference_speaker %>
         <%= link_to t("actions.new_speaker", scope: "decidim.admin"), new_conference_speaker_path(current_conference), class: "button button__sm button__secondary new" %>
      <% end %>
    </h1>
  </div>

  <div class="filters__section">
    <div class="fcell search">
      <%= form_tag "", method: :get do %>
        <div class="input-group">
          <%= search_field_tag :q, @query,label: false, class: "input-group-field", placeholder: t(".search") %>
          <div class="input-group-button">
            <button type="submit" class="text-secondary" aria-label="<%= t("decidim.search.term_input_placeholder") %>">
              <%= icon "search-line", class: "fill-secondary w-4 h-4" %>
            </button>
          </div>
        </div>
      <% end %>
    </div>
  </div>

  <div class="table-stacked">
    <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.conference_speaker.fields.full_name", scope: "decidim.admin") %></th>
          <th><%= t("models.conference_speaker.fields.position", scope: "decidim.admin") %></th>
          <th><%= t("models.conference_speaker.fields.affiliation", scope: "decidim.admin") %></th>
          <th><%= t("models.conference_speaker.fields.actions", scope: "decidim.admin") %></th>
        </tr>
      </thead>
      <tbody>
        <% @conference_speakers.each do |speaker| %>
          <% speaker_presenter = Decidim::Admin::ConferenceSpeakerPresenter.new(speaker) %>
          <tr>
            <td data-label="<%= t("models.conference_speaker.fields.full_name", scope: "decidim.admin") %>">
              <%= speaker_presenter.name %>
            </td>
            <td data-label="<%= t("models.conference_speaker.fields.position", scope: "decidim.admin") %>">
              <%= translated_attribute(speaker.position) %>
            </td>
            <td data-label="<%= t("models.conference_speaker.fields.affiliation", scope: "decidim.admin") %>">
              <%= translated_attribute(speaker.affiliation) %>
            </td>
            <td class="table-list__actions" data-label="<%= t("models.conference_speaker.fields.actions", scope: "decidim.admin") %>">
              <button type="button" data-controller="dropdown" data-target="actions-conference-speaker-<%= speaker.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: speaker_presenter.name) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-conference-speaker-<%= speaker.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to? :update, :conference_speaker, speaker: speaker %>
                    <li class="dropdown__item">
                      <%= link_to edit_conference_speaker_path(current_conference, speaker), class: "dropdown__button" do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <% if allowed_to? :update, :conference_speaker, speaker: speaker %>
                    <% if speaker.published? %>
                      <li class="dropdown__item">
                        <%= link_to unpublish_conference_speaker_path(current_conference, speaker.id), method: :put, class: "dropdown__button" do %>
                          <%= icon "close-circle-line" %>
                          <%= t("actions.unpublish", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% else %>
                      <li class="dropdown__item">
                        <%= link_to publish_conference_speaker_path(current_conference, speaker.id), method: :put, class: "dropdown__button" do %>
                          <%= icon "check-line" %>
                          <%= t("actions.publish", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% end %>

                    <hr>
                  <% end %>

                  <% if allowed_to? :destroy, :conference_speaker, speaker: speaker %>
                    <li class="dropdown__item">
                      <%= link_to conference_speaker_path(current_conference, speaker), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
  <%= decidim_paginate @conference_speakers %>
</div>
